package com.ruoyi.business.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.MessageCenter;
import com.ruoyi.business.service.IMessageCenterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消息中心Controller
 * 
 * @author asher
 * @date 2021-12-10
 */
@RestController
@RequestMapping("/business/message_center")
public class MessageCenterController extends BaseController
{
    @Autowired
    private IMessageCenterService messageCenterService;

    /**
     * 查询消息中心列表
     */
    @PreAuthorize("@ss.hasPermi('business:message_center:list')")
    @GetMapping("/list")
    public TableDataInfo list(MessageCenter messageCenter)
    {
        startPage();
        List<MessageCenter> list = messageCenterService.selectMessageCenterList(messageCenter);
        return getDataTable(list);
    }

    /**
     * 导出消息中心列表
     */
    @PreAuthorize("@ss.hasPermi('business:message_center:export')")
    @Log(title = "消息中心", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MessageCenter messageCenter)
    {
        List<MessageCenter> list = messageCenterService.selectMessageCenterList(messageCenter);
        ExcelUtil<MessageCenter> util = new ExcelUtil<MessageCenter>(MessageCenter.class);
        return util.exportExcel(list, "消息中心数据");
    }

    /**
     * 获取消息中心详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:message_center:query')")
    @GetMapping(value = "/{messageId}")
    public AjaxResult getInfo(@PathVariable("messageId") Long messageId)
    {
        return AjaxResult.success(messageCenterService.selectMessageCenterByMessageId(messageId));
    }

    /**
     * 新增消息中心
     */
    @PreAuthorize("@ss.hasPermi('business:message_center:add')")
    @Log(title = "消息中心", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MessageCenter messageCenter)
    {
        return toAjax(messageCenterService.insertMessageCenter(messageCenter));
    }

    /**
     * 修改消息中心
     */
    @PreAuthorize("@ss.hasPermi('business:message_center:edit')")
    @Log(title = "消息中心", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MessageCenter messageCenter)
    {
        return toAjax(messageCenterService.updateMessageCenter(messageCenter));
    }

    /**
     * 删除消息中心
     */
    @PreAuthorize("@ss.hasPermi('business:message_center:remove')")
    @Log(title = "消息中心", businessType = BusinessType.DELETE)
	@DeleteMapping("/{messageIds}")
    public AjaxResult remove(@PathVariable Long[] messageIds)
    {
        return toAjax(messageCenterService.deleteMessageCenterByMessageIds(messageIds));
    }
}
